package com.gsm.controller;

import com.gsm.entity.Result;
import com.gsm.po.Chapter;
import com.gsm.service.ChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程章节(Chapter)表控制层
 *
 * @author wjq
 * @since 2020-11-28 09:59:49
 */
@RestController
@RequestMapping("chapter")
public class ChapterController {
    @Autowired
    private ChapterService chapterService;

    /**
     * 新增
     */
    @PostMapping("chapter")
    public Result insertChapter(@RequestBody Chapter chapter) {
        Result result = chapterService.insertChapter(chapter);
        return result;
    }

    /**
     * 根据 id 删除数据
     */
    @DeleteMapping("chapter/{chapterId}")
    public Result deleteChapterByChapterId(@PathVariable("chapterId") Long chapterId) {
        Result result = chapterService.deleteChapterByChapterId(chapterId);
        return result;
    }

    /**
     * 根据 id 删除数据
     */
    @PostMapping("chapter/ids/{subjectId}")
    public Result deleteChapterByChapterIds(@PathVariable("subjectId")Long subjectId,@RequestBody List<Long> ids) {
        Result result = chapterService.deleteChapterByChapterIds(subjectId,ids);
        return result;
    }

    /**
     * 根据 id 修改单条数据
     */
    @PutMapping("chapter/{chapterId}")
    public Result updateChapterByChapterId(@PathVariable("chapterId") Long chapterId, @RequestBody Chapter chapter) {
        chapter.setChapterId(chapterId);
        Result result = chapterService.updateChapterByChapterId(chapter);
        return result;
    }

    /**
     * 根据 id 查询单条数据
     */
    @GetMapping("chapter/{chapterId}")
    public Result selectChapterByChapterId(@PathVariable("chapterId") Long chapterId) {
        Result result = chapterService.selectChapterByChapterId(chapterId);
        return result;
    }

    /**
     * 根据条件查询 List
     */
    @GetMapping("chapterList")
    public Result selectChapterList(Chapter chapter) {
        Result result = chapterService.selectChapterList(chapter);
        return result;
    }

    /**
     * 根据课程id查询 章节List
     */
    @GetMapping("chapterList/{subjectId}")
    public Result selectChapterListBySubjectId(@PathVariable("subjectId")Long subjectId) {
        Result result = chapterService.selectChapterListBySubjectId(subjectId);
        return result;
    }

    /**
     * 根据课程id 查询 章节List 和 课时list
     */
    @GetMapping("chapterListAndCourseList/{subjectId}")
    public Result selectChapterListAndCourseListBySubjectId(@PathVariable("subjectId")Long subjectId) {
        Result result = chapterService.selectChapterListAndCourseListBySubjectId(subjectId);
        return result;
    }

    /**
     * 根据id排序
     */
    @PutMapping("order/{subjectId}")
    public Result updateChapterShowOrder(@PathVariable("subjectId")Long subjectId,@RequestBody List<Long> ids) {
        Result result = chapterService.updateChapterShowOrder(subjectId,ids);
        return result;
    }
}